package edu.biola.matthew;

import java.util.Scanner;

/**
 * Created by seankang on 2/2/15.
 */
public class DateType {


	public static final int LESS = -1;
	public static final int EQUAL = 0;
	public static final int GREATER = 1;

	/**
	 * Similar to C++ -- the default constructor
	 */
	public DateType() {
		year = 2000;
		month = 1;
		day = 1;
		System.out.println("default constructor");
	}

	/**
	 * constructor.
	 * @param newMonth
	 * @param newDay
	 * @param newYear
	 */
	public DateType(int newMonth, int newDay, int newYear) {
		year = newYear;
		month = newMonth;
		day = newDay;
		System.out.println("special constructor executed.");
	}


	/**
	 * In C++ the default boolean type is bool
	 *   In Java, it is boolean
	 * @param newMonth
	 * @param newDay
	 * @param newYear
	 * @return
	 */
	public boolean setDate(int newMonth, int newDay, int newYear) {
		year = newYear;
		month = newMonth;
		day = newDay;


		return true;
	}


	/**
	 * Java naming convention for function -- start with a lowerCase.
	 *    Accessor typically always is named: getNameOfMemberVariable
	 * @return
	 */
	public int getYear() {
		return year;
	}

	/**
	 * Java naming convention for function -- start with a lowerCase.
	 *    Accessor typically always is named: getNameOfMemberVariable
	 * @return
	 */
	public int getMonth() {
		return month;
	}

	/**
	 * Java naming convention for function -- start with a lowerCase.
	 *    Accessor typically always is named: getNameOfMemberVariable
	 * @return
	 */
	public int getDay() {
		return day;
	}



	public void readDate() {
		System.out.println("Read in the information of a date: ");



		System.out.println("The month is: ");
		Scanner s = new Scanner(System.in);
		month = s.nextInt();

		System.out.println("The day is: ");
		day = s.nextInt();
		System.out.println("The year is: ");
		year = s.nextInt();

	}


	public void printDate() {
		System.out.println(""+month+"/"+day + "/"+ year);
	}


	public int comparedTo(DateType aDate) {
		if (year > aDate.getYear())
		{
			return GREATER;
		}
		else if (aDate.getYear()==year)
		{
			if (month > aDate.getMonth())
			{
				return GREATER;
			}
			else if (aDate.getMonth()==month)
			{
				if (day > aDate.getDay())
				{
					return GREATER;
				}
				else if (aDate.getDay()==day)
				{
					return EQUAL;
				}
				else
				{
					return LESS;
				}
			}
			else
			{
				return LESS;
			}
		}
		else
		{
			return LESS;
		}
	}


	public int comparedCentury(DateType aDate) {
		//Replace the return statement with your own code here
		int century = year/100;
		int aCentury = aDate.getYear()/100;
		if (century > aCentury)
		{
			return GREATER;
		}
		else if (aCentury==century)
		{
			return EQUAL;
		}
		else
		{
			return LESS;
		}
	}




	private int year;
	private int month;
	private int day;

}
